//
//  NSDictionary+SWAdd.m
//  QZMJ
//
//  Created by 腾程－ios1 on 16/12/15.
//  Copyright © 2016年 曾少伟. All rights reserved.
//

#import "NSDictionary+SWAdd.h"

@implementation NSDictionary (SWAdd)

- (NSString *)convertToJSONStr {
    NSError *error;
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:self
                                                       options:NSJSONWritingPrettyPrinted // Pass 0 if you don't care about the readability of the generated string
                                                         error:&error];
    
    NSString *jsonString = @"";
    if (! jsonData){
        NSLog(@"Got an error: %@", error);
    }else{
        jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    }
    jsonString = [jsonString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];  //去除掉首尾的空白字符和换行字符
    [jsonString stringByReplacingOccurrencesOfString:@"\n" withString:@""];
    return jsonString;
}


@end
